<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.3 The java.io Package</TITLE>
<META NAME="author" CONTENT="Mark Grand and Jonathan Knudsen">
<META NAME="date" CONTENT="Fri Aug  8 16:06:36 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java Fundamental Classes Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Fundamental Classes Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Introduction</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JFC-CH-1-SECT-3">1.3 The java.io Package</A></h2>

<P CLASS=para>
The <tt CLASS=literal>java.io</tt> package contains the 
classes that handle fundamental input and output operations
in Java. Almost all fundamental I/O in Java is based on streams. 
A stream represents
a flow of data, or a channel of communication, with a reading
process at one end of the stream and a writing process at the other end,
at least conceptually. 
As of Java 1.1, the <tt CLASS=literal>java.io</tt>
package is the largest of the fundamental packages.
See <A HREF="ch06_01.htm">Chapter 6, <i>I/O</i></A>, for a more in-depth description
of the basic I/O capabilities provided by this package.

<P CLASS=para>
Java 1.0 supports only
byte streams. The <tt CLASS=literal>InputStream</tt> class is
the superclass of all of the Java 1.0 byte input streams, while 
<tt CLASS=literal>OutputStream</tt> is the superclass of all 
the byte output streams. A number of other byte stream classes
extend the functionality of these basic streams. For example, the
<tt CLASS=literal>FileInputStream</tt> and <tt CLASS=literal>FileOutputStream</tt>
classes read from and write to files, respectively, while
<tt CLASS=literal>DataInputStream</tt> and <tt CLASS=literal>DataOutputStream</tt>
read and write binary representations of the primitive Java data
types. The main problem with these byte streams is
that they do not handle the conversion between the Unicode character
set used internally by Java and other character sets used when reading
or writing data. 

<P CLASS=para>
As of Java 1.1, <tt CLASS=literal>java.io</tt> contains classes 
that represent character streams. These character stream classes
convert other character encodings that appear in I/O streams to and
from Unicode characters. The 
<tt CLASS=literal>Reader</tt> class is the superclass of all the Java
1.1 character input streams, while <tt CLASS=literal>Writer</tt>
is the superclass of all character output streams.
Many of the reader and writer classes have analogous behavior to
corresponding byte stream classes. For instance, 
<tt CLASS=literal>FileReader</tt> and <tt CLASS=literal>FileWriter</tt>
are character streams that read from and write to files, respectively.

<P CLASS=para>
The <tt CLASS=literal>InputStreamReader</tt> and 
<tt CLASS=literal>OutputStreamWriter</tt> classes provide a bridge
between byte streams and character streams. If you wrap an
<tt CLASS=literal>InputStreamReader</tt> around an
<tt CLASS=literal>InputStream</tt> object, the bytes in the byte
stream are read and converted to characters using the character
encoding scheme specified by the <tt CLASS=literal>InputStreamReader</tt>.
Likewise, you can wrap an <tt CLASS=literal>OutputStreamWriter</tt>
around any <tt CLASS=literal>OutputStream</tt> object, which allows you to
write characters and have them converted to bytes.

<P CLASS=para>
As of Java 1.1, <tt CLASS=literal>java.io</tt> also contains
classes to support <I CLASS=emphasis>object serialization</I>. Object
serialization is the ability to write the complete state of
an object to an output stream, and then later recreate that
object by reading in the serialized state from an input stream.
The <tt CLASS=literal>ObjectOutputStream</tt> and
<tt CLASS=literal>ObjectInputStream</tt> classes handle serializing
and deserializing objects, respectively. These classes
provide basic serialization capabilities for all objects
that implement the <tt CLASS=literal>Serializable</tt> interface.
<A HREF="ch07_01.htm">Chapter 7, <i>Object Serialization</i></A>, provides a more detailed explanation of the new
object serialization functionality in Java 1.1.

<P CLASS=para>
The <tt CLASS=literal>RandomAccessFile</tt> class is the only
class in <tt CLASS=literal>java.io</tt> 
that does not use a stream for reading or writing data.
As its name implies, <tt CLASS=literal>RandomAccessFile</tt>
provides nonsequential access to a file, so you can use
it to read from or write to specific locations in a file.

<P CLASS=para>
The <tt CLASS=literal>File</tt> class represents a file on the
local filesystem. The class provides methods to identify
a file, both in terms of its path and its filename.
There are also methods that retrieve information about a file,
such as its status as a directory or a file, its length, and
its last modification time.

<P CLASS=para>
See <A HREF="ch11_01.htm">Chapter 11, <i>The java.io Package</i></A>, for complete reference material on all of the
classes in the <tt CLASS=literal>java.io</tt> package.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>The java.lang.reflect Package</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>The java.net Package</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
